﻿/***********************************************************************************************
 * 
 * ProjectName: WMSSoft.Lib.WinKStart
 * 
 * Description: Class to read Styles from Disk
 * 
 * Created:     21.08.2014
 * 
 * Author:      matthias wagler - matthias@WMSSoft.de
 * 
 * Copyright:   Copyright 2014 by WMSSoft.net
 * 
 * License:     GPLv3
 * 
 * History:     21.08.2014 - matthias wagler matthias@WMSSoft.de   -   Created
 * 
 **********************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using WMSSoft.Lib.Basic;
using WMSSoft.Lib.Basic.Xml;
using WMSSoft.Lib.Const;
using WMSSoft.Lib.Enums;

namespace WMSSoft.Lib.WinKStart
{
    public class cStyleReader
    {
        private Dictionary<string, Classes.Styles.cUIStyle> _StyleViewNames = new Dictionary<string, Classes.Styles.cUIStyle>();
        private string _ActiveStyleName = "Default";

        #region Properties

        public Dictionary<string, Classes.Styles.cUIStyle> StyleViewNames
        {
            get { return _StyleViewNames; }
        }

        public Dictionary<string, string> StyleSettings
        {
            get {
                if (_ActiveStyleName.Length > 0)
                {
                    if (_StyleViewNames.ContainsKey(_ActiveStyleName) == true)
                    {
                        return _StyleViewNames[_ActiveStyleName].StyleSettings;
                    }
                    else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_STYLE_DOESNT_EXIST));
                }
                else
                    return null;
            }
        }
        #endregion

        #region Public Methods

        /// <summary>
        /// Load all defined Styles from Disk
        /// </summary>
        public void Load()
        {
            //implements code
            if (System.IO.Directory.Exists(cUserSettingsReader.StylesPath) == true)
            {
                string[] sStyleFiles = System.IO.Directory.GetFiles(cUserSettingsReader.StylesPath);
                Classes.Styles.cUIStyle tmpStyle = null;

                foreach (string File in sStyleFiles)
                {
                    tmpStyle = null;

                    if (System.IO.File.Exists(File) == true)
                    {
                        tmpStyle = this.LoadStyle(File);
                    }

                    if (tmpStyle != null)
                    {
                        //Add Style to Dictionary
                        if (_StyleViewNames.ContainsKey(tmpStyle.Metadata.Name) == false)
                            _StyleViewNames.Add(tmpStyle.Metadata.Name, tmpStyle);
                    }
                }

                string sFirstStylename = GetFirstStyleName();
                if (sFirstStylename.Length > 0)
                {
                    SetActiveStyle(sFirstStylename);
                }                
            }
        }

        /// <summary>
        /// Set the active used style
        /// </summary>
        /// <param name="Stylename">Name of the Style to use</param>
        public void SetActiveStyle(string Stylename)
        {
            //TODO: implements code
            if (_StyleViewNames.ContainsKey(Stylename) == true)
                _ActiveStyleName = Stylename;
            //else
            //    throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_SETSTYLE_STYLE_NOT_EXIST));            
        }

        public Classes.Styles.cUIWindow GetWindowStyle()
        {
            try
            {
                if (_ActiveStyleName.Length > 0)
                {
                    if (_StyleViewNames.ContainsKey(_ActiveStyleName) == true)
                    {
                        return _StyleViewNames[_ActiveStyleName].Window;
                    }
                    else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_STYLE_DOESNT_EXIST));
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_ACTIVE_STYLE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WHILE_READING_WINDOW_STYLE), Ex);
            }
        }

        public Classes.Styles.cUIElementImage GetImageStyle(string Elementname)
        {
            try
            {
                if (_ActiveStyleName.Length > 0)
                {
                    if (_StyleViewNames.ContainsKey(_ActiveStyleName) == true)
                    {
                        switch (Elementname)
                        {

                            case StyleElements.STYLE_ELEMENT__PICTURE_USER_PICTURE:
                                return _StyleViewNames[_ActiveStyleName].Window.Elements.UserPicture;
                            case StyleElements.STYLE_ELEMENT__PICTURE_SEARCH_PICTURE:
                                return _StyleViewNames[_ActiveStyleName].Window.Elements.SearchPicture;
                            case StyleElements.STYLE_ELEMENT__PICTURE_SELECTOR_PICTURE:
                                return _StyleViewNames[_ActiveStyleName].Window.Elements.RegionButtons.Selector;
                            case StyleElements.STYLE_ELEMENT__PICTURE_SELECT_NEXT_PICTURE:
                                return _StyleViewNames[_ActiveStyleName].Window.Elements.RegionButtons.SelectNext;
                            case StyleElements.STYLE_ELEMENT__PICTURE_SELECT_PREVIOUS_PICTURE:
                                return _StyleViewNames[_ActiveStyleName].Window.Elements.RegionButtons.SelectPrevious;
                            default:
                                return null;
                        }
                    }
                    else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_STYLE_DOESNT_EXIST));
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_ACTIVE_STYLE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WHILE_READING_WINDOW_STYLE), Ex);
            }
        }

        public Classes.Styles.cUIElement GeteElementStyle(string Elementname)
        {
            try
            {
                if (_ActiveStyleName.Length > 0)
                {
                    if (_StyleViewNames.ContainsKey(_ActiveStyleName) == true)
                    {
                        switch (Elementname.ToUpper())
                        {
                            case "USERCOMPUTERNAME":
                                return _StyleViewNames[_ActiveStyleName].Window.Elements.UserComputerName;
                            case "SEARCH":
                                return _StyleViewNames[_ActiveStyleName].Window.Elements.Search;
                            case "SEARCHBOX":
                                return _StyleViewNames[_ActiveStyleName].Window.Elements.SearchBox;
                            default:
                                return null;
                        }
                    }
                    else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_STYLE_DOESNT_EXIST));
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_ACTIVE_STYLE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WHILE_READING_WINDOW_STYLE), Ex);
            }
        }

        public Classes.Styles.cUIElementRegionPosition GetRegionPositionStyle()
        {
            try
            {
                if (_ActiveStyleName.Length > 0)
                {
                    if (_StyleViewNames.ContainsKey(_ActiveStyleName) == true)
                    {
                        return _StyleViewNames[_ActiveStyleName].Window.Elements.RegionPositions;
                    }
                    else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_STYLE_DOESNT_EXIST));
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_ACTIVE_STYLE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WHILE_READING_REGION_POSITION_STYLE), Ex);
            }
        }

        public Classes.Styles.cUIElementRegion GetRegionStyle(string Elementname)
        {
            try
            {
                if (_ActiveStyleName.Length > 0)
                {
                    if (_StyleViewNames.ContainsKey(_ActiveStyleName) == true)
                    {
                        if (_StyleViewNames[_ActiveStyleName].Window.Elements.Regions.ContainsKey(Elementname) == true)
                            return _StyleViewNames[_ActiveStyleName].Window.Elements.Regions[Elementname];
                        else
                            return _StyleViewNames[_ActiveStyleName].Window.Elements.AllRegions;
                    }
                    else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_STYLE_DOESNT_EXIST));
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_ACTIVE_STYLE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WHILE_READING_WINDOW_STYLE), Ex);
            }
        }

        public Classes.Styles.cUIElementPanel GetPanelStyle(string Elementname)
        {
            try
            {
                if (_ActiveStyleName.Length > 0)
                {
                    if (_StyleViewNames.ContainsKey(_ActiveStyleName) == true)
                    {
                        if (_StyleViewNames[_ActiveStyleName].Window.Elements.Panels.ContainsKey(Elementname) == true)
                            return _StyleViewNames[_ActiveStyleName].Window.Elements.Panels[Elementname];
                        else
                            return _StyleViewNames[_ActiveStyleName].Window.Elements.AllPanels;
                    }
                    else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_STYLE_DOESNT_EXIST));
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_ACTIVE_STYLE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WHILE_READING_WINDOW_STYLE), Ex);
            }
        }

        public Classes.Styles.cUIElementRegionButton GetRegionButtonStyle(string Elementname)
        {
            try
            {
                if (_ActiveStyleName.Length > 0)
                {
                    if (_StyleViewNames.ContainsKey(_ActiveStyleName) == true)
                    {
                        if (_StyleViewNames[_ActiveStyleName].Window.Elements.RegionButtons.Buttons.ContainsKey(Elementname) == true)
                            return _StyleViewNames[_ActiveStyleName].Window.Elements.RegionButtons.Buttons[Elementname];
                        else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_REGION_BUTTON_STYLE_NOT_EXIST));
                    }
                    else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_STYLE_DOESNT_EXIST));
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_ACTIVE_STYLE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WHILE_READING_WINDOW_STYLE), Ex);
            }
        }

        public Classes.Styles.cUIElementRegionButtons GetRegionButtonsStyle()
        {
            try
            {
                if (_ActiveStyleName.Length > 0)
                {
                    if (_StyleViewNames.ContainsKey(_ActiveStyleName) == true)
                    {
                        return _StyleViewNames[_ActiveStyleName].Window.Elements.RegionButtons;                        
                    }
                    else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_STYLE_DOESNT_EXIST));
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_ACTIVE_STYLE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WHILE_READING_WINDOW_STYLE), Ex);
            }
        }

        public Classes.Styles.cStyleInfo GetStyleInfo(string Stylename)
        {
            try
            {
                if (_ActiveStyleName.Length > 0)
                {
                    if (_StyleViewNames.ContainsKey(_ActiveStyleName) == true)
                    {
                        return _StyleViewNames[_ActiveStyleName].Metadata;
                    }
                    else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_STYLE_DOESNT_EXIST));
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_ACTIVE_STYLE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WHILE_READING_WINDOW_STYLE), Ex);
            }
        }
       
        #endregion

        #region Private Methods
        /// <summary>
        /// Returns the first available Style to use
        /// </summary>
        /// <returns>Stylename</returns>
        private string GetFirstStyleName()
        {
            try
            {
                if (_StyleViewNames.Count > 0)
                {
                    Dictionary<string, Classes.Styles.cUIStyle>.KeyCollection oKeys = _StyleViewNames.Keys;
                    string sFirstStyleName = "";
                    foreach (string StyleName in oKeys)
                    {
                        sFirstStyleName = StyleName;
                        break;
                    }
                    return sFirstStyleName;
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_STYLES_DEFINED));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_CANT_READ_FIRST_STYLENAME), Ex);
            }
        }

        /// <summary>
        /// Load a Style - File as object
        /// </summary>
        /// <param name="Filename">Style - Filename to load</param>
        /// <returns></returns>
        Classes.Styles.cUIStyle LoadStyle(string Filename)
        {
            try
            {
                Classes.Styles.cUIStyle oStyle = new Classes.Styles.cUIStyle();

                System.Xml.XmlDocument oXMLDocuement = new System.Xml.XmlDocument();
                oXMLDocuement.Load(Filename);
                //Search Root - Node
                System.Xml.XmlNode RootNode = cXmlHelpers.GetRootNode(oXMLDocuement);

                if (RootNode.ChildNodes.Count > 0)
                {
                    //Process SubChilds
                    foreach (System.Xml.XmlNode SubNode in RootNode.ChildNodes)
                    {
                        if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__METADATA)
                            oStyle.Metadata = ProcessLoad_MetaData(SubNode);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__SETTINGS)
                            oStyle.StyleSettings = ProcessLoad_Settings(SubNode);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__WINDOW)
                            oStyle.Window = ProcessLoad_Window(SubNode);
                    }
                }

                return oStyle;
            }
            catch (Exception Ex)
            {
                string sErrorMsg = LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_STYLE_FROM_FILE);
                sErrorMsg = sErrorMsg.Replace("##FILENAME##", Filename);
                throw new Exception(sErrorMsg, Ex);
            }
        }

        /// <summary>
        /// Load the Style Metadata
        /// </summary>
        /// <param name="Node">Xml Node to load from</param>
        /// <returns>Configuration object with Meta data</returns>
        Classes.Styles.cStyleInfo ProcessLoad_MetaData(System.Xml.XmlNode Node)
        {
            try
            {
                if (Node != null)
                {
                    Classes.Styles.cStyleInfo oStyleInfo = new Classes.Styles.cStyleInfo();

                    foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                    {
                        if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__DATE && SubNode.InnerText != null && SubNode.InnerText.Length > 0)
                            oStyleInfo.Date = DateTime.Parse(SubNode.InnerText);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__NAME && SubNode.InnerText != null && SubNode.InnerText.Length > 0)
                            oStyleInfo.Name = SubNode.InnerText;
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__DESCRIPTION && SubNode.InnerText != null && SubNode.InnerText.Length > 0)
                            oStyleInfo.Description = SubNode.InnerText;
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__VERSION && SubNode.InnerText != null && SubNode.InnerText.Length > 0)
                        {
                            if (basic_helpers.isNumeric(SubNode.InnerText) == true)
                                oStyleInfo.Version = Convert.ToInt32(SubNode.InnerText);
                            else
                                oStyleInfo.Version = 0;
                        }
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__AUTHOR && SubNode.InnerText != null && SubNode.InnerText.Length > 0)
                            oStyleInfo.Author = SubNode.InnerText;
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__MAIL && SubNode.InnerText != null && SubNode.InnerText.Length > 0)
                            oStyleInfo.Mail = SubNode.InnerText;
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__WEB && SubNode.InnerText != null && SubNode.InnerText.Length > 0)
                            oStyleInfo.Web = SubNode.InnerText;
                    }
                    return oStyleInfo;
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_METADATA_NODE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_STYLES_METADATA), Ex);
            }
        }

        /// <summary>
        /// Load the Style settings
        /// </summary>
        /// <param name="Node">Xml Node to load from</param>
        /// <returns>Dictionary with Settings</returns>
        Dictionary<string, string> ProcessLoad_Settings(System.Xml.XmlNode Node)
        {
            try
            {
                if (Node != null)
                {
                    Dictionary<string, string> dictSettings = new Dictionary<string, string>();

                    foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                    {
                        if (dictSettings.ContainsKey(SubNode.Name) == false)
                            dictSettings.Add(SubNode.Name, SubNode.InnerText);
                    }

                    return dictSettings;
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_SETTINGS_NODE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_STYLES_SETTINGS), Ex);
            }
        }

        Color GetColorFromNode(System.Xml.XmlNode Node)
        {
            try
            {
                byte iColorPartAlpha = 255;
                byte iColorPartRed = 255;
                byte iColorPartGreen = 255;
                byte iColorPartBlue = 255;

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__COLOR_PART_ALPHA && SubNode.InnerText.Length > 0)
                        iColorPartAlpha = Convert.ToByte(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__COLOR_PART_RED && SubNode.InnerText.Length > 0)
                        iColorPartRed = Convert.ToByte(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__COLOR_PART_GREEN && SubNode.InnerText.Length > 0)
                        iColorPartGreen = Convert.ToByte(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__COLOR_PART_BLUE && SubNode.InnerText.Length > 0)
                        iColorPartBlue = Convert.ToByte(SubNode.InnerText);
                }

                return Color.FromArgb(iColorPartAlpha, iColorPartRed, iColorPartGreen, iColorPartBlue);
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_COLOR_FROM_XML), Ex);
            }
        }

        Classes.Styles.cUIGradientStyle ProcessLoad_GradientStyle(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIGradientStyle oGradientStyle = new Classes.Styles.cUIGradientStyle();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__GRADIENT_ANGLE)
                        oGradientStyle.Angle = Convert.ToDouble(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__GRADIENT_ANGLE)
                        oGradientStyle.Offset = Convert.ToDouble(SubNode.InnerText);
                }

                return oGradientStyle;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_GRADIENT_STYLE_FROM_XML), Ex);
            }
        }

        Classes.Styles.cUIBorderStyle ProcessLoad_BorderStyle(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIBorderStyle oBorderStyle = new Classes.Styles.cUIBorderStyle();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__WIDTH)
                        oBorderStyle.Width = Convert.ToInt32(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__COLOR)
                        oBorderStyle.Color = GetColorFromNode(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__VISIBLE)
                        oBorderStyle.Visible = Boolean.Parse(SubNode.InnerText);
                }

                return oBorderStyle;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_BORDER_STYLE_FROM_XML), Ex);
            }
        }

        Classes.Styles.cUIElementImage ProcessLoad_UIElement_Image(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIElementImage oImageElement = new Classes.Styles.cUIElementImage();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HEIGHT)
                        oImageElement.Height = Convert.ToInt32(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__WIDTH)
                        oImageElement.Width = Convert.ToInt32(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__SOURCE)
                        oImageElement.Source = SubNode.InnerText;
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__STRETCH)
                        oImageElement.Stretch = (Stretch)Enum.Parse(typeof(Stretch), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__STRETCH_DIRECTION)
                        oImageElement.StretchDirection = (System.Windows.Controls.StretchDirection)Enum.Parse(typeof(System.Windows.Controls.StretchDirection), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__VISIBLE)
                        oImageElement.Visible = (Visibility)Enum.Parse(typeof(Visibility), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__MARGIN)
                        oImageElement.Margin = ProcessLoad_Margin(SubNode);
                }

                return oImageElement;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_WINDOW_IMAGE_STYLE), Ex);
            }
        }

        Classes.Styles.cUIElement ProcessLoad_UIElement(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIElement oElement = new Classes.Styles.cUIElement();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BACKGROUNDCOLOR)
                        oElement.BackgroundColor = GetColorFromNode(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_FAMILY)
                        oElement.FontFamily = SubNode.InnerText;
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BORDER)
                        oElement.Border = ProcessLoad_BorderStyle(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_COLOR)
                        oElement.FontColor = GetColorFromNode(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_SIZE)
                        oElement.FontSize = Convert.ToDouble(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_STYLE)
                        oElement.FontStyle = ParseFontStyle(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_WEIGHT)
                        oElement.FontWeight = ParseFontWeight(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HORIZONTAL_ALIGN)
                        oElement.HorizontalAlign = (eXMLHorizontalAlign)Enum.Parse(typeof(eXMLHorizontalAlign), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__VERTICAL_ALIGN)
                        oElement.VerticalAlign = (eXMLVerticalAlign)Enum.Parse(typeof(eXMLVerticalAlign), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__VISIBLE)
                        oElement.Visible = (Visibility)Enum.Parse(typeof(Visibility), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__MARGIN)
                        oElement.Margin = ProcessLoad_Margin(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__PADDING)
                        oElement.Padding = ProcessLoad_Padding(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HEIGHT)
                        oElement.Height = Convert.ToDouble(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__WIDTH)
                        oElement.Width = Convert.ToDouble(SubNode.InnerText);
                }

                return oElement;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_WINDOW_ELEMENT_STYLE), Ex);
            }
        }

        Classes.Styles.cUIElementHeader ProcessLoad_Header(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIElementHeader oHeader = new Classes.Styles.cUIElementHeader();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BACKGROUNDCOLOR)
                        oHeader.BackgroundColor = GetColorFromNode(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BORDER)
                        oHeader.Border = ProcessLoad_BorderStyle(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_FAMILY)
                        oHeader.FontFamily = SubNode.InnerText;
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_COLOR)
                        oHeader.FontColor = GetColorFromNode(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_SIZE)
                        oHeader.FontSize = Convert.ToDouble(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_STYLE)
                        oHeader.FontStyle = ParseFontStyle(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_WEIGHT)
                        oHeader.FontWeight = ParseFontWeight(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HORIZONTAL_ALIGN)
                        oHeader.HorizontalAlign = (eXMLHorizontalAlign)Enum.Parse(typeof(eXMLHorizontalAlign), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__VERTICAL_ALIGN)
                        oHeader.VerticalAlign = (eXMLVerticalAlign)Enum.Parse(typeof(eXMLVerticalAlign), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__VISIBLE)
                        oHeader.Visible =(Visibility)Enum.Parse(typeof(Visibility), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HEIGHT)
                        oHeader.Height = Convert.ToInt32(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__MARGIN)
                        oHeader.Margin = ProcessLoad_Margin(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__PADDING)
                        oHeader.Padding = ProcessLoad_Padding(SubNode);
                }

                return oHeader;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_REGION_PANEL_HEADER_STYLE), Ex);
            }
        }

        Classes.Styles.cUIElementData ProcessLoad_Data(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIElementData oData = new Classes.Styles.cUIElementData();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BACKGROUNDCOLOR)
                        oData.BackgroundColor = GetColorFromNode(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BORDER)
                        oData.Border = ProcessLoad_BorderStyle(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_FAMILY)
                        oData.FontFamily = SubNode.InnerText;
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_COLOR)
                        oData.FontColor = GetColorFromNode(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_SIZE)
                        oData.FontSize = Convert.ToDouble(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_STYLE)
                        oData.FontStyle = ParseFontStyle(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__FONT_WEIGHT)
                        oData.FontWeight = ParseFontWeight(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HORIZONTAL_ALIGN)
                        oData.HorizontalAlign = (eXMLHorizontalAlign)Enum.Parse(typeof(eXMLHorizontalAlign), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__VERTICAL_ALIGN)
                        oData.VerticalAlign = (eXMLVerticalAlign)Enum.Parse(typeof(eXMLVerticalAlign), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__VISIBLE)
                        oData.Visible = (Visibility)Enum.Parse(typeof(Visibility), SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__LINEHEIGHT)
                        oData.LineHeight = Convert.ToInt32(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__MARGIN)
                        oData.Margin = ProcessLoad_Margin(SubNode);
                }

                return oData;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_REGION_PANEL_DATA_STYLE), Ex);
            }
        }

        Classes.Styles.cUIElementRegionPosition ProcessLoad_RegionPositions(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIElementRegionPosition oRegionPositions = new Classes.Styles.cUIElementRegionPosition();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HEIGHT)
                        oRegionPositions.Height = Convert.ToDouble(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__MARGIN)
                        oRegionPositions.Margin = ProcessLoad_Margin(SubNode);
                }

                return oRegionPositions;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_REGION_POSITIONS), Ex);
            }
        }

        Classes.Styles.cUIElementRegion ProcessLoad_AllRegions(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIElementRegion oAllElementRegions = new Classes.Styles.cUIElementRegion();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BACKGROUNDCOLOR)
                        oAllElementRegions.BackgroundColor = GetColorFromNode(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HEADER)
                        oAllElementRegions.Header = ProcessLoad_Header(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__DATA)
                        oAllElementRegions.Data = ProcessLoad_Data(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__NAME)
                        oAllElementRegions.ElementID = SubNode.InnerText;
                }

                return oAllElementRegions;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_ALL_REGIONS_STYLE), Ex);
            }
        }

        Dictionary<string, Classes.Styles.cUIElementRegion> ProcessLoad_Regions(System.Xml.XmlNode Node)
        {
            try
            {
                Dictionary<string, Classes.Styles.cUIElementRegion> oElementRegions = new Dictionary<string, Classes.Styles.cUIElementRegion>();
                Classes.Styles.cUIElementRegion oRegion = null;

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    oRegion = null;

                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_REGION)
                    {
                        oRegion = ProcessLoad_AllRegions(SubNode);
                        if (oRegion != null)
                            if (oElementRegions.ContainsKey(oRegion.ElementID) == false)
                                oElementRegions.Add(oRegion.ElementID, oRegion);
                        
                    }

                }

                return oElementRegions;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_NAMED_REGION_STYLES), Ex);
            }
        }

        Classes.Styles.cUIElementPanel ProcessLoad_AllPanels(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIElementPanel oAllElementPanels = new Classes.Styles.cUIElementPanel();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BACKGROUNDCOLOR)
                        oAllElementPanels.BackgroundColor = GetColorFromNode(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HEADER)
                        oAllElementPanels.Header = ProcessLoad_Header(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__DATA)
                        oAllElementPanels.Data = ProcessLoad_Data(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__NAME)
                        oAllElementPanels.ElementID = SubNode.InnerText;
                }

                return oAllElementPanels;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_ALL_PANEL_STYLES), Ex);
            }
        }

        Dictionary<string, Classes.Styles.cUIElementPanel> ProcessLoad_Panels(System.Xml.XmlNode Node)
        {
            try
            {
                Dictionary<string, Classes.Styles.cUIElementPanel> _oPanels = new Dictionary<string, Classes.Styles.cUIElementPanel>();
                Classes.Styles.cUIElementPanel oPanel = null;

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    oPanel = null;

                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_PANEL)
                    {
                        oPanel = ProcessLoad_AllPanels(SubNode);
                        if (oPanel != null)
                            if (_oPanels.ContainsKey(oPanel.ElementID) == false)
                                _oPanels.Add(oPanel.ElementID, oPanel);

                    }

                }

                return _oPanels;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_NAMED_PANEL_STYLES), Ex);
            }
        }

        Classes.Styles.cUIElementRegionButton ProcessLoad_RegionButton(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIElementRegionButton oRegionButton = new Classes.Styles.cUIElementRegionButton();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__WIDTH)
                        oRegionButton.Width = Convert.ToInt32(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__IMAGE)
                        oRegionButton.Image = ProcessLoad_UIElement_Image(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__LABEL)
                        oRegionButton.Label = ProcessLoad_UIElement(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__REGIONID)
                        oRegionButton.RegionID = SubNode.InnerText;                  
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__VISIBLE)
                        oRegionButton.Visible = bool.Parse(SubNode.InnerText);

                }

                return oRegionButton;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_REGIONBUTTON_STYLE), Ex);
            }
        }

        Classes.Styles.cUIElementRegionButtons ProcessLoad_RegionButtons(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIElementRegionButtons oRegionButtons = new Classes.Styles.cUIElementRegionButtons();
                Classes.Styles.cUIElementRegionButton otmpRegionButton = null;

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HEIGHT)
                        oRegionButtons.Height = Convert.ToInt32(SubNode.InnerText);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__SELECTOR)
                        oRegionButtons.Selector = ProcessLoad_UIElement_Image(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__MARGIN)
                        oRegionButtons.Margin = ProcessLoad_Margin(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__SELECT_NEXT)
                        oRegionButtons.SelectNext = ProcessLoad_UIElement_Image(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__SELECT_PREVIOUS)
                        oRegionButtons.SelectPrevious = ProcessLoad_UIElement_Image(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_REGIONBUTTON)
                    {
                        otmpRegionButton = null;
                        otmpRegionButton = ProcessLoad_RegionButton(SubNode);

                        if (oRegionButtons.Buttons.ContainsKey(otmpRegionButton.RegionID) == false)
                        {
                            oRegionButtons.Buttons.Add(otmpRegionButton.RegionID, otmpRegionButton);
                        }
                    }
                        
                }

                return oRegionButtons;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_REGIONBUTTONS_STYLE), Ex);
            }
        }


        Classes.Styles.cUIWindowElements ProcessLoad_WindowElements(System.Xml.XmlNode Node)
        {
            try
            {
                Classes.Styles.cUIWindowElements oWindowElements = new Classes.Styles.cUIWindowElements();

                foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                {
                    if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_USERPICTURE)
                        oWindowElements.UserPicture = ProcessLoad_UIElement_Image(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_USERCOMPUTERNAME)
                        oWindowElements.UserComputerName = ProcessLoad_UIElement(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_SEARCHPICTURE)
                        oWindowElements.SearchPicture = ProcessLoad_UIElement_Image(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_SEARCH_LABEL)
                        oWindowElements.Search = ProcessLoad_UIElement(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_SEARCHBOX)
                        oWindowElements.SearchBox = ProcessLoad_UIElement(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_REGION_POSITION)
                        oWindowElements.RegionPositions = ProcessLoad_RegionPositions(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_AllREGIONS)
                        oWindowElements.AllRegions = ProcessLoad_AllRegions(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_REGIONS)
                        oWindowElements.Regions = ProcessLoad_Regions(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_ALLPANELS)
                        oWindowElements.AllPanels = ProcessLoad_AllPanels(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_PANELS)
                        oWindowElements.Panels = ProcessLoad_Panels(SubNode);
                    else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS_REGIONBUTTONS)
                        oWindowElements.RegionButtons = ProcessLoad_RegionButtons(SubNode);
                }

                return oWindowElements;
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_WINDOW_ELEMENTS_STYLE), Ex);
            }
        }

        /// <summary>
        /// Load Window Style elements
        /// </summary>
        /// <param name="Node">Xml Node to load from</param>
        /// <returns>Window Configuration - Object with the styles for window and subelements</returns>
        Classes.Styles.cUIWindow ProcessLoad_Window(System.Xml.XmlNode Node)
        {
            try
            {
                if (Node != null)
                {
                    Classes.Styles.cUIWindow oWindow = new Classes.Styles.cUIWindow();

                    foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                    {
                        if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__DRAWINGMODE)
                            oWindow.DrawingMode = (eDrawingMode)Enum.Parse(typeof(eDrawingMode), SubNode.InnerText);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BACKGROUNDCOLORSTART)
                            oWindow.BackgroundColorStart = GetColorFromNode(SubNode);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BACKGROUNDCOLOREND)
                            oWindow.BackgroundColorEnd = GetColorFromNode(SubNode);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__GRADIENT)
                            oWindow.Gradient = ProcessLoad_GradientStyle(SubNode);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BORDER)
                            oWindow.BorderStyle = ProcessLoad_BorderStyle(SubNode);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__ELEMENTS)
                            oWindow.Elements = ProcessLoad_WindowElements(SubNode);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__HEIGHT)
                            oWindow.Height = Convert.ToDouble(SubNode.InnerText);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__WIDTH)
                            oWindow.Width = Convert.ToDouble(SubNode.InnerText);
                    }

                    return oWindow;
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_WINDOW_NODE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_STYLES_WINDOW), Ex);
            }
        }

        private FontStyle ParseFontStyle(string Value)
        {
            try
            {
                switch (Value.ToUpper())
                {
                    case "ITALIC":
                        return FontStyles.Italic;
                    case "NORMAL":
                        return FontStyles.Normal;
                    case "OBLIQUE":
                        return FontStyles.Oblique;
                    default:
                        string sErrMsg = LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WRONG_FONTSTYLE_VALUE);
                        sErrMsg = sErrMsg.Replace("##ENUMVALUE##", Value);
                        throw new Exception(sErrMsg);
                }
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_CANT_PARSE_FONTSTYLE), Ex);
            }
        }

        private FontWeight ParseFontWeight(string Value)
        {
            try
            {
                switch (Value.ToUpper())
                {
                    case "BLACK":
                        return FontWeights.Black;
                    case "BOLD":
                        return FontWeights.Bold;
                    case "DEMIBOLD":
                        return FontWeights.DemiBold;
                    case "EXTRABLACK":
                        return FontWeights.ExtraBlack;
                    case "EXTRABOLD":
                        return FontWeights.ExtraBold;
                    case "EXTRALIGHT":
                        return FontWeights.ExtraLight;
                    case "HEAVY":
                        return FontWeights.Heavy;
                    case "LIGHT":
                        return FontWeights.Light;
                    case "MEDIUM":
                        return FontWeights.Medium;
                    case "NORMAL":
                        return FontWeights.Normal;
                    case "REGULAR":
                        return FontWeights.Regular;
                    case "SEMIBOLD":
                        return FontWeights.SemiBold;
                    case "THIN":
                        return FontWeights.Thin;
                    case "ULTRABLACK":
                        return FontWeights.UltraBlack;
                    case "ULTRABOLD":
                        return FontWeights.UltraBold;
                    case "ULTRALIGHT":
                        return FontWeights.UltraLight;
                    default:
                        string sErrMsg = LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_WRONG_FONTWEIGHT_VALUE);
                        sErrMsg = sErrMsg.Replace("##ENUMVALUE##", Value);
                        throw new Exception(sErrMsg);
                }
                
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_CANT_PARSE_FONTWEIGHT), Ex);
            }
        }

        Thickness ProcessLoad_Margin(System.Xml.XmlNode Node)
        {
            try
            {
                if (Node != null)
                {
                    double iTopMargin = 0.0;
                    double iBottomMargin = 0.0;
                    double iLeftMargin = 0.0;
                    double iRightMargin = 0.0;

                    Classes.Styles.cUIWindow oWindow = new Classes.Styles.cUIWindow();

                    foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                    {
                        if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__LEFT)
                            iLeftMargin = Convert.ToDouble(SubNode.InnerText);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__TOP)
                            iTopMargin = Convert.ToDouble(SubNode.InnerText);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__RIGHT)
                            iRightMargin = Convert.ToDouble(SubNode.InnerText);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BOTTOM)
                            iBottomMargin = Convert.ToDouble(SubNode.InnerText);
                    }

                    return new Thickness(iLeftMargin, iTopMargin, iRightMargin, iBottomMargin);
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_MARGIN_NODE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_MARGIN), Ex); 
            }
        }

        Thickness ProcessLoad_Padding(System.Xml.XmlNode Node)
        {
            try
            {
                if (Node != null)
                {
                    double iTopMargin = 0.0;
                    double iBottomMargin = 0.0;
                    double iLeftMargin = 0.0;
                    double iRightMargin = 0.0;

                    Classes.Styles.cUIWindow oWindow = new Classes.Styles.cUIWindow();

                    foreach (System.Xml.XmlNode SubNode in Node.ChildNodes)
                    {
                        if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__LEFT)
                            iLeftMargin = Convert.ToDouble(SubNode.InnerText);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__TOP)
                            iTopMargin = Convert.ToDouble(SubNode.InnerText);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__RIGHT)
                            iRightMargin = Convert.ToDouble(SubNode.InnerText);
                        else if (SubNode.Name == XMLNodeNames.STYLE_XMLNODE__BOTTOM)
                            iBottomMargin = Convert.ToDouble(SubNode.InnerText);
                    }

                    return new Thickness(iLeftMargin, iTopMargin, iRightMargin, iBottomMargin);
                }
                else throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_NO_PADDING_NODE));
            }
            catch (Exception Ex)
            {
                throw new Exception(LanguageStrings.GetText(Texte.ErrorMessages.STYLE_READER__ERROR_UNABLE_TO_LOAD_PADDING), Ex);
            }
        }

        #endregion    

    }
}
